<?php 

function M($model_name){
	$m = new Model();
	return $m->table($model_name);
}

function D($model_name){
	$path = APP_PATH.'/Model/'.$model_name.'Model.class.php';
	if(file_exists($path)){
		require($path);
		$real_model_name = $model_name.'Model';
		$model = new $real_model_name();
		return $model->table($model_name);
	}else{
		exit($model_name.'Model not exists.');
	}
}

//get config 
function C($key){	
	return PHPFun::$config[$key];
}

//make url
function U($c='Index',$a='index',$p=''){
	$url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
	$url.='?c='.$c.'&a='.$a;
	$url = $p?$url.'&'.$p:$url;
	return $url;
}

//Public, get request data
function I($v){
	$arr = explode('.',$v);
	list($method,$key) = $arr;
	if($key){
		switch($method){
			case 'get':
			return _phpfun_trim($_GET[$key]);
			break;
			
			case 'post':
			return _phpfun_trim($_POST[$key]);
			break;
		}
	}else{
		switch($method){
			case 'get':
			$request = $_GET; 
			break;
			
			case 'post':
			$request = $_POST;
			break;
		}
		
		foreach($request as $key=>$value){
			$r[$key] = _phpfun_trim($value);
		}
		return $r;
	}
}


//Private func
function _phpfun_trim($val){
	return htmlspecialchars($val);
}



?>